/*     */ package dm.jdbc.dbaccess;
/*     */ 
/*     */ import java.net.InetAddress;
/*     */ import java.net.UnknownHostException;
/*     */ import java.sql.SQLException;
/*     */ import org.ietf.jgss.GSSContext;
/*     */ import org.ietf.jgss.GSSException;
/*     */ import org.ietf.jgss.GSSManager;
/*     */ import org.ietf.jgss.GSSName;
/*     */ import org.ietf.jgss.Oid;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class Auth
/*     */ {
/*  26 */   private static String serviceName = "dmserver";
/*     */   
/*  28 */   private String servicePrincipleName = null;
/*     */   
/*  30 */   private AuthInfo authInfo = null;
/*     */   
/*  32 */   private Oid authTypeOid = null;
/*     */   
/*     */   private static String getServerFQDN(String serverName) throws UnknownHostException
/*     */   {
/*  36 */     InetAddress addr = InetAddress.getByName(serverName);
/*  37 */     addr = InetAddress.getByAddress(addr.getAddress());
/*  38 */     String name = addr.getCanonicalHostName();
/*     */     
/*  40 */     return name;
/*     */   }
/*     */   
/*     */   private static String getServicePrincipleName(String serverName) throws UnknownHostException
/*     */   {
/*  45 */     String serverFQDN = getServerFQDN(serverName);
/*     */     
/*  47 */     return serviceName + "@" + serverFQDN;
/*     */   }
/*     */   
/*     */   public Auth(String serverName, int authType) throws UnknownHostException {
/*  51 */     switch (authType) {
/*     */     case 2: 
/*     */       try {
/*  54 */         this.authTypeOid = new Oid("1.2.840.113554.1.2.2");
/*     */       } catch (GSSException e) {
/*  56 */         e.printStackTrace();
/*     */       }
/*     */     }
/*     */     
/*     */     
/*     */ 
/*     */ 
/*  63 */     this.servicePrincipleName = getServicePrincipleName(serverName);
/*     */   }
/*     */   
/*     */   private void doAuth() throws GSSException
/*     */   {
/*  68 */     GSSManager manager = GSSManager.getInstance();
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*  73 */     GSSName serverName = manager.createName(this.servicePrincipleName, 
/*  74 */       GSSName.NT_HOSTBASED_SERVICE);
/*     */     
/*  76 */     GSSContext context = manager.createContext(serverName, this.authTypeOid, 
/*  77 */       null, 0);
/*     */     
/*  79 */     context.requestMutualAuth(false);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*  84 */     byte[] token = new byte[0];
/*     */     
/*  86 */     token = context.initSecContext(token, 0, token.length);
/*     */     
/*  88 */     if (context.isEstablished()) {
/*  89 */       if (token != null) {
/*  90 */         this.authInfo = new AuthInfo(token);
/*  91 */         this.authInfo.setUserName(getContextUserName(context));
/*     */       }
/*     */       
/*  94 */       context.dispose();
/*     */     } else {
/*  96 */       this.authInfo = null;
/*     */     }
/*     */   }
/*     */   
/*     */   public AuthInfo getAuthInfo() throws SQLException {
/*     */     try {
/* 102 */       System.setProperty("javax.security.auth.useSubjectCredsOnly", 
/* 103 */         "false");
/*     */       
/* 105 */       doAuth();
/*     */     }
/*     */     catch (GSSException e) {
/* 108 */       DBError.throwSQLException(e.getMessage());
/*     */     }
/*     */     
/* 111 */     return this.authInfo;
/*     */   }
/*     */   
/*     */   public String getContextUserName(GSSContext context) throws GSSException {
/* 115 */     String userPrincipleName = context.getSrcName().toString();
/* 116 */     String userName = null;
/* 117 */     int index = userPrincipleName.indexOf('@');
/*     */     
/* 119 */     userName = userPrincipleName.substring(0, index);
/*     */     
/* 121 */     return userName;
/*     */   }
/*     */ }


/* Location:              D:\Program Files\DBMS_20150813\jdbc\Dm7JdbcDriver17.jar!\dm\jdbc\dbaccess\Auth.class
 * Java compiler version: 2 (46.0)
 * JD-Core Version:       0.7.1
 */